﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Marmat.Forms
{
    public class TopicBar_GlobalEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            // Dim designerHost As IDesignerHost = CType(context.GetService(GetType(IDesignerHost)), IDesignerHost)
            if (edSvc is object)
            {
                if (context.Instance is TopicBar)
                {
                    switch (context.PropertyDescriptor.Name ?? "")
                    {
                        case "Pages":
                            {
                                var f = new TopicBarCollectionForm((TopicBar)context.Instance);
                                if (f.ShowDialog() == DialogResult.OK)
                                {
                                    value = f.Method_1();
                                }

                                break;
                            }
                    }
                }
            }

            return value;
        }

        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}